package com.gmlive.common.sample.widgets

import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import com.gmlive.common.sample.alert_permission.SettingsCompat
import com.gmlive.common.sample.databinding.ActivityAlertPermissionBinding
import com.gmlive.common.sample.viewbinding.binding
import com.gmlive.common.ui.systembartint.OSUtil

/**
 *
 * @Author Sven
 * @Date 2021/8/5
 * @Email jiangzhimin@inke.cn
 */
class AlertWindowActivity : AppCompatActivity() {

    private val binding: ActivityAlertPermissionBinding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.apply {
            requestButton.isVisible = false

            requestButton.setOnClickListener {
                SettingsCompat.instance.requestPermission(this@AlertWindowActivity)
            }
        }

        val canDrawOverlays = SettingsCompat.instance.canDrawOverlays(this)
        Log.i("SettingsCompat", "canDrawOverlays = $canDrawOverlays")
    }

    override fun onResume() {
        super.onResume()

        buildDeviceInfo()
    }

    private fun buildDeviceInfo() {
        val osVersion = Build.VERSION.SDK_INT
        val isVivo = OSUtil.isVivo()
        val alertWindow = SettingsCompat.instance.canDrawOverlays(this)

        val deviceInfo = "Android版本: $osVersion\nVIVO系统: $isVivo\nSYSTEM_ALERT_WINDOW: $alertWindow"

        binding.deviceInfo.text = deviceInfo

        binding.requestButton.isVisible = !alertWindow
    }
}